home *** CD-ROM | disk | FTP | other *** search
- surface
- spasm(
- float frequency = 5,
- pbm = 0.5,
- pg = 0.5;
-
- /* granite stuff */
- float g_Kd = .8,
- g_Ka = .2;
-
- /* blue marble stuff */
- float bm_Ks = .4,
- bm_Kd = .6,
- bm_Ka = .1,
- bm_roughness = .1,
- bm_txtscale = 1;
- color bm_specularcolor = 1)
- {
-
- float smod = mod(s*frequency,1),
- tmod = mod(t*frequency,1);
-
- point NN;
- float y, z, r;
- float sum = 0;
- float i, freq = 7.0;
- color bm_Ci, g_Ci;
-
- point PP; /* scaled point in shader space */
- float csp; /* color spline parameter */
- point Nf; /* forward-facing normal */
- point V; /* for specular() */
- float pixelsize, twice, scale, weight, turbulence;
-
- /* do blue_marble */
- {
- /* Obtain a forward-facing normal for lighting calculations. */
- Nf = faceforward( normalize(N), I);
- V = normalize(-I);
-
- /*
- * Compute "turbulence" a la [PERLIN85]. Turbulence is a sum of
- * "noise" components with a "fractal" 1/f power spectrum. It gives the
- * visual impression of turbulent fluid flow (for example, as in the
- * formation of blue_marble from molten color splines!). Use the
- * surface element area in texture space to control the number of
- * noise components so that the frequency content is appropriate
- * to the scale. This prevents aliasing of the texture.
- */
- PP = transform("shader", P) * bm_txtscale;
- pixelsize = sqrt(area(PP));
- twice = 2 * pixelsize;
- turbulence = 0;
- for (scale = 1; scale > twice; scale /= 2)
- turbulence += scale * noise(PP/scale);
-
- /* Gradual fade out of highest-frequency component near limit */
- if (scale > pixelsize) {
- weight = (scale / pixelsize) - 1;
- weight = clamp(weight, 0, 1);
- turbulence += weight * scale * noise(PP/scale);
- }
-
- /*
- * Magnify the upper part of the turbulence range 0.75:1
- * to fill the range 0:1 and use it as the parameter of
- * a color spline through various shades of blue.
- */
- csp = clamp(4 * turbulence - 3, 0, 1);
- bm_Ci = color spline(csp,
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.20, 0.20, 0.30), /* medium blue */
- color (0.20, 0.20, 0.30), /* medium blue */
- color (0.20, 0.20, 0.30), /* medium blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.15, 0.15, 0.26), /* medium dark blue */
- color (0.15, 0.15, 0.26), /* medium dark blue */
- color (0.10, 0.10, 0.20), /* dark blue */
- color (0.10, 0.10, 0.20), /* dark blue */
- color (0.25, 0.25, 0.35), /* pale blue */
- color (0.10, 0.10, 0.20) /* dark blue */
- );
-
- /* Multiply this color by the diffusely reflected light. */
- bm_Ci *= bm_Ka*ambient() + bm_Kd*diffuse(Nf);
-
- /* Adjust for opacity. */
- Oi = Os;
- bm_Ci = bm_Ci * Oi;
-
- /* Add in specular highlights. */
- bm_Ci += bm_specularcolor * bm_Ks * specular(Nf,V,bm_roughness);
- }
-
- /* do wood */
- {
- for (i = 0; i < 6; i = i + 1) {
- sum = sum + abs(.5 - noise( 4 * freq * I))/freq ;
- freq *= 2;
- }
- g_Ci = Cs * sum * (g_Ka + g_Kd *diffuse(faceforward( normalize(N),I )) ) ;
- }
-
- /* combine the two */
- if(((smod < pg) && (tmod<pbm)) || ((smod > pg) && (tmod>pbm)))
- Ci=g_Ci;
- else
- Ci=bm_Ci;
- }
-
-
-